Is `super` local variable?
Posted
by Michael
on Stack Overflow
See other posts from Stack Overflow
or by Michael
Published on 2010-06-03T01:08:10Z
Indexed on
2010/06/03
1:14 UTC
Read the original article
Hit count: 176
objective-c
// A : Parent
@implementation A
-(id) init
{
// change self here then return it
}
@end A
A *a = [[A alloc] init];
a. Just wondering, if self is a local variable or global? If it's local then what is the point of self = [super init]
in init
? I can successfully define some local variable and use like this, why would I need to assign it to self
.
-(id) init
{
id tmp = [super init];
if(tmp != nil) {
//do stuff
}
return tmp;
}
b. If [super init]
returns some other object instance and I have to overwrite self
then I will not be able to access A's methods any more, since it will be completely new object? Am I right?
c. super
and self
pointing to the same memory and the major difference between them is method lookup order. Am I right?
sorry, don't have Mac to try, learning theory as for now...
© Stack Overflow or respective owner